package reign.engine.structures;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public abstract class Deck {

	private String name;
	private int id;
	private List<Card> cards;
	private Card [] startingCards;
	
	public Deck(String Name,int ID)
	{
		name = Name;
		id = ID;
	}
	
	public Deck(String Name,int ID,Card [] addMe)
	{
		name = Name;
		id = ID;
		startingCards = addMe;
		buildDeck(addMe);
	}
	
	public String getName()
	{
		return name;
	}
	
	public void reset()
	{
		buildDeck(startingCards);
		shuffle();
	}
	
	public int getID()
	{
		return id;
	}
	
	public void buildDeck(Card [] addMe)
	{
		cards = Arrays.asList(addMe);
	}
	
	public void shuffle()
	{
		Random rand = new Random();
		for(int i = 0; i < 1000;i++)
		{
			int slot1 = rand.nextInt(999);
			int slot2 = rand.nextInt(999);
			Card temp = cards.get(slot2);
			Card temp2 = cards.get(slot1);
			cards.remove(slot2);
			cards.remove(slot1);
			cards.add(slot1,temp);
			cards.add(slot2,temp2);
		}
	}
	
	public Card draw()
	{
		Card returnMe = cards.get(0);
		cards.remove(0);
		return returnMe;
	}
	
	public Card[] draw(int number)
	{
		Card[] returnMe = new Card[number];
		for(int i = 0; i < number;i++)
		{
			returnMe[i] = cards.get(i);
			cards.remove(i);
		}
		return returnMe;
		
	}
	
	public void printDeck()
	{
		Iterator<Card> tempIterator = cards.iterator();
		while(tempIterator.hasNext())
		{
			System.out.println(tempIterator.next().getName());
		}
	}
	
}
